package com.ems.controller.supers.questions;

import com.ems.pojo.data.RequestData;
import com.ems.pojo.data.ResultData;
import com.ems.pojo.data.RetunResult;
import com.ems.pojo.data.ReturnPageResult;
import com.ems.pojo.questions.ShortAnswer;
import com.ems.pojo.questions.Subject;
import com.ems.service.supers.questions.ShortAnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Auther: 伟伟
 * @Date: 2019/10/27
 * @Description: 简答题
 * @Version: 1.0
 */
@Controller
@CrossOrigin //允许所有请求跨域
@RequestMapping("/shortAnswerController")
public class ShortAnswerController {
    @Autowired
    @Qualifier("shortAnswerService")
    private ShortAnswerService shortAnswerService;

    //添加简答题
    @ResponseBody
    @RequestMapping("/addShortAnswer")
    public ResultData addShortAnswer(@RequestBody List<ShortAnswer> shortAnswer){
        shortAnswerService.addShortAnswer(shortAnswer);
        return RetunResult.AssemblyData();
    }

    //删除简答题
    @ResponseBody
    @RequestMapping("/deleteShortAnswer")
    public ResultData deleteShortAnswer(@RequestBody List<ShortAnswer> shortAnswerList){
        shortAnswerService.deleteShortAnswer(shortAnswerList);
        return RetunResult.AssemblyData();
    }

    //修改简答题
    @ResponseBody
    @RequestMapping("/updateShortAnswer")
    public ResultData updateShortAnswer(@RequestBody ShortAnswer shortAnswer){
        shortAnswerService.updateShortAnswer(shortAnswer);
        return RetunResult.AssemblyData();
    }

    //查询对应的选择题
    @ResponseBody
    @RequestMapping("/findShortAnswer")
    public ResultData findShortAnswer(@RequestBody RequestData requestData){
        ReturnPageResult.setPageHelperInfo(requestData);
        List<Subject> list = shortAnswerService.findShortAnswer(requestData);
        return ReturnPageResult.AssemblyData(list);
    }

}
